<script lang="ts" setup>
import { ref, Ref, computed, watch } from "vue";
import studentCV from '@/class/studentCV';
import { studentCVStoreHook } from "@/store/modules/studentCV";


const dialogFormVisible = computed(() => props.isShow);
const formLabelWidth = '100px'

//件
const emits = defineEmits(["closeEdit", "success"])
//保存
const update = async () => {
    await studentCVStoreHook().update(rowData.value)
        .then(rep => {
            if (rep.code == 200) {
                console.log(rep.msg)
            }
        })
    emits("success")

}
const close = () => {
    emits("closeEdit")
}

//传参
const props = defineProps({
    isShow: Boolean,
    info: studentCV
})

const rowData: Ref<studentCV> = ref<studentCV>({
    id: "",
    userId: "",
    phone: "",
    education: 0,
    age: "",
    name: "",
    sex: "",
    desiredOccupation: "",
    fileId: "",
    createTime: "",
    updateTime: "",
})

//监听
watch(() => props.info, (newInfo) => {
    if (newInfo) {
        rowData.value = {
            id: newInfo.id,
            userId: newInfo.userId,
            phone: newInfo.phone,
            education: newInfo.education,
            age: newInfo.age,
            name: newInfo.name,
            sex: newInfo.sex,
            desiredOccupation: newInfo.desiredOccupation,
            fileId: newInfo.fileId,
            createTime: newInfo.createTime,
            updateTime: newInfo.updateTime,
        }
    }
})

//选择框
const value = ref(0)
const options = [
    {
        value: 0,
        label: '专科',
    },
    {
        value: 1,
        label: '本科',
    },
    {
        value: 2,
        label: '硕士',
    }
]
const labelPosition = ref("left");
</script>

<template>
    <el-dialog v-model="dialogFormVisible" title="新增" width="40%" @close="$emit('closeEdit')" draggable center>
        <el-form ref="formRef" :model="rowData" label-width="100px" :validate-on-rule-change="false" :inline="false"  label-position="left">
            <el-form-item label="ID" prop="id" :label-width="formLabelWidth">
                <el-input v-model="rowData.id" disabled />
            </el-form-item>
            <el-form-item label="姓名" prop="name" :label-width="formLabelWidth">
                <el-input v-model="rowData.name" autocomplete="off" />
            </el-form-item>
            <el-form-item label="年龄" prop="age" :label-width="formLabelWidth">
                <el-input v-model="rowData.age" autocomplete="off" />
            </el-form-item>
            <el-form-item label="手机号" prop="phone" :label-width="formLabelWidth">
                <el-input v-model="rowData.phone" autocomplete="off" />
            </el-form-item>
            <el-form-item label="性别" prop="sex" :label-width="formLabelWidth">
                <el-input v-model="rowData.sex" type="text" autocomplete="off" />
            </el-form-item>
            <el-form-item label="学历" prop="education" :label-width="formLabelWidth">
                <el-select v-model="rowData.education" class="m-2" placeholder="学历">
                    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="期望的职业" prop="desiredOccupation" :label-width="formLabelWidth">
                <el-input v-model="rowData.desiredOccupation" type="text" disabled />
            </el-form-item>
            <el-form-item label="简历ID" prop="fileId" :label-width="formLabelWidth">
                <el-input v-model="rowData.fileId" type="text" disabled />
            </el-form-item>
            <el-form-item label="创建时间" prop="createTime" :label-width="formLabelWidth">
                <el-input v-model="rowData.createTime" type="data" disabled />
            </el-form-item>
            <el-form-item label="更新时间" prop="updateTime" :label-width="formLabelWidth">
                <el-input v-model="rowData.updateTime" type="data" disabled />
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="close">关闭</el-button>
                <el-button type="primary" @click="update">
                    修改
                </el-button>
            </span>
        </template>
    </el-dialog>
</template>
